home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / tcisam.zip / IREWRITE.C < prev    next >
Text File  |  1987-08-21  |  1KB  |  42 lines

  1. /*
  2.  * IREWRITE.C - update a record
  3.  *
  4.  *                      Copyright (c) 1987, Jim Mischel
  5.  * Modifications:
  6.  *
  7.  * 08/13/87 - jim - original coding
  8.  * 08/21/87 - jim - copy source to data buffer before writing
  9.  */
  10.  
  11. #include "inxdefs.h"
  12.  
  13. /*
  14.  * irewrite() - update the current data record with the data at 'source'.
  15.  * Returns 0 if successful, error status otherwise.  If the key at 'source'
  16.  * is not the same as the key in the current data record, I_INVKEY is
  17.  * returned and no update is performed.  Since the only integrity check
  18.  * made is a simple key comparison, if duplicate keys are permitted, it
  19.  * is possible to write a record where it doesn't belong.
  20.  */
  21. int irewrite(void *d, void *src)
  22. {
  23.   df_rec *db_control = (df_rec *)d;
  24.   char *source = (char *)src;
  25.  
  26.   /* check delete flag */
  27.   if (db_control->df_flags & DF_DELETE)
  28.     return(ierror(I_INVKEY));
  29.  
  30.   /* see if keys are equal */
  31.   if ((*db_control->df_cmp)((source+db_control->df_key_offset),
  32.                             db_control->df_key_ptr))
  33.     return(ierror(I_INVKEY));           /* error: keys not equal */
  34.  
  35.   /* ok, write the record */
  36.   memcpy(db_control->df_dat_buff,source,db_control->df_rec_size);
  37.   if (iwrite_dat(db_control,source,db_control->df_dat_ptr))
  38.     return(ierrno);                     /* write error */
  39.  
  40.   return(ierror(0));
  41. } /* irewrite */
  42.